package commons.base.luncene;

import java.io.IOException;
import java.util.List;

import org.apache.lucene.queryparser.classic.ParseException;

public class IndexUser extends BaseIndexService {

	protected IndexUser() throws IOException {
		super("/data/log/indexes/user");
	}

	public IndexUser update(UserDoc doc) throws IOException {
		indexDir.getUpdater().updateDocument("userId", doc.getUserId(), 
				new StringDocumentBuilder()
				.addField("userName", doc.getUserName())
				.addField("userId", doc.getUserId())
				.addField("captainName", doc.getCaptainName())
				.build());
		return this;
	}

	public List<UserDoc> searchByUserName(String username) throws IOException, ParseException {
		return super.search("userName", username, UserDoc.class);
	}
	
	public List<UserDoc> searchByCaptainName(String captainName) throws IOException, ParseException {
		return super.search("captainName", captainName, UserDoc.class);
	}

	public static class UserDoc {
		private String userId;
		private String userName;
		private String captainName;

		public UserDoc() {

		}

		public UserDoc(String userId, String userName, String captainName) {
			super();
			this.userId = userId;
			this.userName = userName;
			this.captainName = captainName;
		}

		public String getUserId() {
			return userId;
		}

		public void setUserId(String userId) {
			this.userId = userId;
		}

		public String getUserName() {
			return userName;
		}

		public void setUserName(String userName) {
			this.userName = userName;
		}

		public String getCaptainName() {
			return captainName;
		}

		public void setCaptainName(String captainName) {
			this.captainName = captainName;
		}
		
	}
}
